package org.jeecg.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.domain.dto.OrdersServeDto;
import org.jeecg.domain.dto.RenDto;
import org.jeecg.domain.po.OrdersServe;
import org.jeecg.domain.vo.OrdersServeAll;
import org.jeecg.domain.vo.OrdersServeVO;
import org.jeecg.service.OrdersServeService;
import org.jeecg.mapper.OrdersServeMapper;
import org.jeecg.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author 32327
* @description 针对表【orders_serve(服务单表)】的数据库操作Service实现
* @createDate 2025-01-03 08:02:49
*/
@Service
public class OrdersServeServiceImpl extends ServiceImpl<OrdersServeMapper, OrdersServe>
    implements OrdersServeService{
    @Autowired
    private OrdersServeMapper ordersServeMapper;
    @Override
    public ResponseResult findPage(OrdersServeDto dto) {
        Page<OrdersServeVO> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        System.out.println(dto);
        dto.setServeProviderType(3);
        List<OrdersServeVO> list = ordersServeMapper.findPage(page,dto);
        page.setRecords(list);
        return ResponseResult.okResult(page);
    }

    @Override
    public ResponseResult findServeName() {
        List<OrdersServeVO> list = ordersServeMapper.findServeName();
        return ResponseResult.okResult(list);
    }

    @Override
    public ResponseResult updateRen(RenDto dto) {
        System.out.println(dto);
        OrdersServe one = this.getOne(Wrappers.<OrdersServe>lambdaQuery().eq(OrdersServe::getId, dto.getId()));
            if (one.getTaskStatus()==0) {
                one.setInstitutionStaffId(dto.getInstitutionStaffId());
                one.setTaskStatus(1);
            } else if (one.getTaskStatus() == 1) {
                one.setServeBeforeImgs(dto.getServeBeforeImgs());
                one.setServeBeforeIllustrate(dto.getServeBeforeIllustrate());
                one.setRealServeStartTime(new Date());
                one.setTaskStatus(2);
            } else if (one.getTaskStatus() == 2) {
                one.setServeAfterImgs(dto.getServeBeforeImgs());
                one.setServeAfterIllustrate(dto.getServeAfterIllustrate());
                one.setRealServeEndTime(new Date());
                one.setTaskStatus(3);
            }
        System.out.println(one);
        boolean b = this.updateById(one);
        return b?ResponseResult.okResult("修改成功"):ResponseResult.errorResult(500,"修改失败");
    }

    @Override
    public ResponseResult exitOrder(String id) {
        System.out.println(id);
        OrdersServe one = this.getOne(Wrappers.<OrdersServe>lambdaQuery().eq(OrdersServe::getId, id));
        one.setTaskStatus(5);
        boolean b = this.updateById(one);
        return b?ResponseResult.okResult("取消成功"):ResponseResult.errorResult(500,"取消失败");
    }

    @Override
    public ResponseResult startServe(RenDto dto) {
        System.out.println(dto);
        OrdersServe one = this.getOne(Wrappers.<OrdersServe>lambdaQuery().eq(OrdersServe::getId, dto.getId()));
        one.setServeBeforeImgs(dto.getServeBeforeImgs());
        one.setServeBeforeIllustrate(dto.getServeBeforeIllustrate());
        one.setRealServeStartTime(new Date());
        one.setTaskStatus(2);
        boolean b = this.updateById(one);
        return b?ResponseResult.okResult("修改成功"):ResponseResult.errorResult(500,"修改失败");
    }

    @Override
    public ResponseResult delOrder(String id) {
        boolean b = this.removeById(id);
        return b?ResponseResult.okResult("删除成功"):ResponseResult.errorResult(500,"删除失败");
    }

    @Override
    public ResponseResult getOneById(String id) {
        OrdersServeAll ordersServe = ordersServeMapper.getOneById(id);
        return ResponseResult.okResult(ordersServe);
    }
}




